package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.ElderlyInfo;
import com.zzyl.nursing.domain.FamilyMemberElderList;
import com.zzyl.nursing.dto.ElderlyPersonDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceService deviceService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定家人
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody ElderlyPersonDto elderlyPersonDto){
        familyMemberService.familyAdd(elderlyPersonDto);
        return success();
    }

    /**
     * 绑定家人
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult myFamily(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        List<FamilyMemberElderList> elderlyInfo =  familyMemberService.SelectMyFamilyList(pageNum,pageSize);
        return success(elderlyInfo);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("查询家人列表")
    public AjaxResult my(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        List<ElderlyInfo>  elderlyInfo =  familyMemberService.SelectMyFamilyListSelectPage(pageNum,pageSize);
        return success(elderlyInfo);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 解绑老人
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("解绑老人")
    public AjaxResult deleteById( Long id)
    {
        familyMemberService.deleteById(id);
        return success();
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(String iotId ,
                                               Long endTime,
                                               Long startTime,
                                               String functionId)
    {
        List<Map<String,Object>> map = familyMemberService.queryDeviceDataListByDay(iotId,endTime,startTime,functionId);
        return success(map);
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(String iotId ,
                                               Long endTime,
                                               Long startTime,
                                               String functionId)
    {
        List<Map<String,Object>> map = familyMemberService.queryDeviceDataListByWeek(iotId,endTime,startTime,functionId);
        return success(map);
    }

}
